/*
-----------------------------------------------------------------------------
Filename:    ExampleFrameListener.h
Description: Defines an example frame listener which responds to frame events.
This frame listener just moves a specified camera around based on
keyboard and mouse movements.
Mouse:    Freelook
W or Up:  Forward
S or Down:Backward
A:        Step left
D:        Step right
             PgUp:     Move upwards
             PgDown:   Move downwards
             F:        Toggle frame rate stats on/off
			 R:        Render mode
             T:        Cycle texture filtering
                       Bilinear, Trilinear, Anisotropic(8)
             P:        Toggle on/off display of camera position / orientation
-----------------------------------------------------------------------------
*/

#ifndef _E_FRAME_LISTENER_H_
#define _E_FRAME_LISTENER_H_

#include <OgreStringConverter.h>
#include <OgreException.h>

//Use this define to signify OIS will be used as a DLL
//(so that dll import/export macros are in effect)
#define OIS_DYNAMIC_LIB
#include <OIS/OIS.h>

#include "eH.h"
namespace engine {
class EApp;

class EFrameListener: public FrameListener, public WindowEventListener
{
  EApp &m_app;
protected:
	void updateStats( void );

public:
	/// Constructor takes a RenderWindow because it uses that to determine input context
  EFrameListener(EApp &app, RenderWindow* pRenderWindow, Camera* pCam, bool bBufferedKeys = false, bool bBufferedMouse = false,
         bool bBufferedJoy = true );

  virtual     ~EFrameListener();

	/// Adjust mouse clipping area
	virtual void  windowResized               ( RenderWindow* pRw );

	/// Unattach OIS before window shutdown (very important under Linux)
	virtual void  windowClosed                ( RenderWindow* pRw );
	virtual bool  processUnbufferedKeyInput   ( const FrameEvent& evt );
	bool          processUnbufferedMouseInput ( const FrameEvent& evt );
  bool          processUnbufferedJoypadInput ( const FrameEvent& evt );
	void          moveCamera                  ();
	void          showDebugOverlay            ( bool bShow );

	// Override frameStarted event to process that (don't care about frameEnded)
	bool          frameStarted                ( const FrameEvent& evt );
	bool          frameEnded                  ( const FrameEvent& evt );

protected:
	Camera*             m_pCamera;

	Vector3             m_TranslateVector;
	RenderWindow*       m_Window;
	bool                m_StatsOn;

	std::string         m_DebugText;

	unsigned int        m_NumScreenShots;
	float               m_MoveScale;
	Degree              m_RotScale;
	// just to stop toggles flipping too fast
	Real                m_TimeUntilNextToggle ;
	Radian              m_RotX, m_RotY;
	TextureFilterOptions m_Filtering;
	int                 m_Aniso;

	int 				        m_SceneDetailIndex ;
	Real                m_MoveSpeed;
	Degree              m_RotateSpeed;
	Overlay*            m_DebugOverlay;

	//OIS Input devices
	OIS::InputManager* 	m_InputManager;
	OIS::Mouse*    		  m_pMouse;
	OIS::Keyboard* 		  m_pKeyboard;
	OIS::JoyStick* 		  m_pJoy;
};

} // end namespace engine

#endif

